package com.example.examplexml;

import java.util.ArrayList;
import java.util.HashMap;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class list2 extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list2);
                
        Bundle receivebundle = this.getIntent().getExtras(); 
        String x = receivebundle.getString("id");
        
        
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
      
       
        String xml = XMLfunctions.getXML("http://210.211.98.84/webicm/ts/ProvinceResult.xml?ProvinceID="+x+"&TSM=227911");
        Document doc = XMLfunctions.XMLfromString(xml);               
                
		//NodeList nodes = doc.getElementsByTagName("result");
        NodeList nodes = doc.getElementsByTagName("item");
        //Element e = (Element)nodes.item(1);
        
		for (int i = 0; i < nodes.getLength(); i++) {							
			HashMap<String, String> map = new HashMap<String, String>();	
			Node itemNode = nodes.item(i);
			
			Element definitionElement = (Element) itemNode;
		// Show Province Code
			NodeList wordDefinitionElements = (definitionElement).getElementsByTagName("ProvinceCode");
			for(int j=0; j <wordDefinitionElements.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements.item(j);				
				map.put("id", XMLfunctions.getValue(wordDefinitionElement, "ProvinceCode"));							
			}
			
		// Show Open Date
			NodeList wordDefinitionElements2 = (definitionElement).getElementsByTagName("OpenDate");
			for(int j=0; j <wordDefinitionElements2.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements2.item(j);				
				map.put("OpenDate", "Opendate:"+XMLfunctions.getValue(wordDefinitionElement, "OpenDate"));					
			}
			
		// Show Special Result
			NodeList wordDefinitionElements3 = (definitionElement).getElementsByTagName("Special_1");
			for(int j=0; j <wordDefinitionElements3.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements3.item(j);							
				map.put("Special_1", "Special: "+XMLfunctions.getValue(wordDefinitionElement, "Special_1"));							
			}

		// Show First Result
			NodeList wordDefinitionElements4 = (definitionElement).getElementsByTagName("First");
			for(int j=0; j <wordDefinitionElements4.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements4.item(j);							
				map.put("First", "First: "+XMLfunctions.getValue(wordDefinitionElement, "First"));							
			}
			
		// Show Second Result
			NodeList wordDefinitionElements5 = (definitionElement).getElementsByTagName("Second");
			for(int j=0; j <wordDefinitionElements5.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements5.item(j);							
				map.put("Second", "Second: "+XMLfunctions.getValue(wordDefinitionElement, "Second"));							
			}
	
		// Show Third Result			
			NodeList wordDefinitionElements6 = (definitionElement).getElementsByTagName("Third");
			for(int j=0; j <wordDefinitionElements6.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements6.item(j);							
				map.put("Third", "Third: "+XMLfunctions.getValue(wordDefinitionElement, "Third"));							
			}
			
		// Show Fourth Result
			NodeList wordDefinitionElements7 = (definitionElement).getElementsByTagName("Fourth");
			for(int j=0; j <wordDefinitionElements7.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements7.item(j);							
				map.put("Fourth", "Fourth: "+XMLfunctions.getValue(wordDefinitionElement, "Fourth"));							
			}
			
		// Show Fifth Result	
			NodeList wordDefinitionElements8 = (definitionElement).getElementsByTagName("Fifth");
			for(int j=0; j <wordDefinitionElements8.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements8.item(j);							
				map.put("Fifth", "Fifth: "+XMLfunctions.getValue(wordDefinitionElement, "Fifth"));							
			}
		
		// Show Sixth Result	
			NodeList wordDefinitionElements9 = (definitionElement).getElementsByTagName("Sixth");
			for(int j=0; j <wordDefinitionElements9.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements9.item(j);							
				map.put("Sixth", "Sixth: "+XMLfunctions.getValue(wordDefinitionElement, "Sixth"));							
			}
		
		// Show Seventh Result	
			NodeList wordDefinitionElements10 = (definitionElement).getElementsByTagName("Seventh");
			for(int j=0; j <wordDefinitionElements10.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements10.item(j);							
				map.put("Seventh", "Seventh: "+XMLfunctions.getValue(wordDefinitionElement, "Seventh"));							
			}
		
		// Show Eighth Result
			NodeList wordDefinitionElements11 = (definitionElement).getElementsByTagName("Eighth");
			for(int j=0; j <wordDefinitionElements11.getLength(); j++){				
				Element wordDefinitionElement = (Element) wordDefinitionElements11.item(j);							
				map.put("Eighth", "Eighth: "+XMLfunctions.getValue(wordDefinitionElement, "Eighth"));							
			}
			mylist.add(map);	
		}		
       // Show Lottery Result
        ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.activity_main, 
                        new String[] { "id","OpenDate", "Special_1", "First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth" }, 
                        new int[] { R.id.item_title, R.id.item_subtitle, R.id.item_subtitle2, R.id.item_subtitle3, R.id.item_subtitle4, R.id.item_subtitle5, R.id.item_subtitle6, R.id.item_subtitle7, R.id.item_subtitle8 });        
        setListAdapter(adapter);
        
        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);	
        lv.setOnItemClickListener(new OnItemClickListener() {
        	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

			}
		});
    }
}